import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SheetSourceVO, SheetSourceForm, SheetSourceQuery } from '@/api/sheet/sheetSource/types';

/**
 * 查询应用数据源列表
 * @param query
 * @returns {*}
 */

export const listSheetSource = (query?: SheetSourceQuery): AxiosPromise<SheetSourceVO[]> => {
  return request({
    url: '/system/sheetSource/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询应用数据源详细
 * @param sheetSourceId
 */
export const getSheetSource = (sheetSourceId: string | number): AxiosPromise<SheetSourceVO> => {
  return request({
    url: '/system/sheetSource/' + sheetSourceId,
    method: 'get'
  });
};

/**
 * 新增应用数据源
 * @param data
 */
export const addSheetSource = (data: SheetSourceForm) => {
  return request({
    url: '/system/sheetSource',
    method: 'post',
    data: data
  });
};

/**
 * 修改应用数据源
 * @param data
 */
export const updateSheetSource = (data: SheetSourceForm) => {
  return request({
    url: '/system/sheetSource',
    method: 'put',
    data: data
  });
};

/**
 * 删除应用数据源
 * @param sheetSourceId
 */
export const delSheetSource = (sheetSourceId: string | number | Array<string | number>) => {
  return request({
    url: '/system/sheetSource/' + sheetSourceId,
    method: 'delete'
  });
};

/**
 * 获取应用绑定的数据眼
 * @param sheetId
 */
export const getSheetDataSourceBySheetId = (sheetId: string | number): AxiosPromise<SheetSourceVO[]> => {
  return request({
    url: '/system/sheetSource/listDataSourceBySheetId/' + sheetId,
    method: 'get'
  });
};
